package com.wck.car.controller;

import com.wck.car.CarBrandDescService;
import com.wck.car.CarParamDescService;
import com.wck.car.CarSeriesDescService;
import com.wck.car.model.CarBrandDesc;
import com.wck.car.model.CarParamDesc;
import com.wck.car.model.CarSeriesDesc;
import com.wck.car.oyz.CarParamDescType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@RestController
public class CarParamDescController {
    @Resource
    CarBrandDescService carBrandDescService;
    @Resource
    CarSeriesDescService carSeriesDescService;
    @Resource
    CarParamDescService carParamDescService;


    @GetMapping("/getCarTypeDesc")
    public void getCarTypeDesc(){
        List<CarBrandDesc> carBrandDescList = carBrandDescService.lambdaQuery().select(CarBrandDesc::getId).list();   //系列ID
        ArrayList<CarParamDesc> carParamDescs = new ArrayList<>();
        carBrandDescList.forEach(c ->{
            List<CarSeriesDesc> carSeriesDescList = carSeriesDescService.lambdaQuery().select(CarSeriesDesc::getId).eq(CarSeriesDesc::getCarBrandId,c.getId()).list();     //型号ID
            carSeriesDescList.forEach(d ->{
                List<CarParamDesc> carTypeInfo = CarParamDescType.getCarTypeInfo(d, c);
                carParamDescs.addAll(carTypeInfo);
            });
        });
        carParamDescService.saveBatch(carParamDescs);
    }
}
